summaryrefslogtreecommitdiff
path: root/app/[lng]/evcp/(evcp)/(procurement)/evaluation/page.tsx
blob: bf30cfc9596feff1043e29353155f2659e431521 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// ================================================================
// 4. PERIODIC EVALUATIONS PAGE - 집계 뷰 지원 (정리된 버전)
// ================================================================

import * as React from "react"
import { Metadata } from "next"
import { type SearchParams } from "@/types/table"
import { getValidFilters } from "@/lib/data-table"
import { Shell } from "@/components/shell"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import { HelpCircle, BarChart3, List, Info } from "lucide-react"
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from "@/components/ui/popover"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Alert, AlertDescription } from "@/components/ui/alert"
import { PeriodicEvaluationsTable } from "@/lib/evaluation/table/evaluation-table"
import { getPeriodicEvaluationsWithAggregation } from "@/lib/evaluation/service"
import { 
  searchParamsEvaluationsCache, 
  type GetEvaluationsSchema 
} from "@/lib/evaluation/validation"
import { InformationButton } from "@/components/information/information-button"
import { useTranslation } from "@/i18n"

export const metadata: Metadata = {
  title: "협력업체 정기평가",
  description: "협력업체 정기평가 진행 현황을 관리합니다.",
}

interface PeriodicEvaluationsPageProps {
  params: Promise<{lng: string}>
  searchParams: Promise<SearchParams>
}

// 프로세스 안내 팝오버 컴포넌트 - 집계 뷰 설명 포함
function ProcessGuidePopover() {
  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button variant="ghost" size="icon" className="h-6 w-6">
          <HelpCircle className="h-4 w-4 text-muted-foreground" />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-96" align="start">
        <div className="space-y-3">
          <div className="space-y-1">
            <h4 className="font-medium">정기평가 프로세스</h4>
            <p className="text-sm text-muted-foreground">
              확정된 평가 대상 업체들에 대한 정기평가 절차입니다.
            </p>
          </div>
          
          <div className="space-y-3 text-sm">
            <div className="flex gap-3">
              <div className="flex h-6 w-6 items-center justify-center rounded-full bg-blue-100 text-xs font-medium text-blue-600">
                1
              </div>
              <div>
                <p className="font-medium">평가 대상 확정</p>
                <p className="text-muted-foreground">평가 대상으로 확정된 업체들의 정기평가가 자동 생성됩니다.</p>
              </div>
            </div>
            <div className="flex gap-3">
              <div className="flex h-6 w-6 items-center justify-center rounded-full bg-blue-100 text-xs font-medium text-blue-600">
                2
              </div>
              <div>
                <p className="font-medium">업체 자료 제출</p>
                <p className="text-muted-foreground">각 업체는 평가에 필요한 자료를 제출 마감일까지 제출해야 합니다.</p>
              </div>
            </div>
            <div className="flex gap-3">
              <div className="flex h-6 w-6 items-center justify-center rounded-full bg-blue-100 text-xs font-medium text-blue-600">
                3
              </div>
              <div>
                <p className="font-medium">평가자 검토</p>
                <p className="text-muted-foreground">지정된 평가자들이 평가표를 기반으로 점수를 매기고 검토합니다.</p>
              </div>
            </div>
            <div className="flex gap-3">
              <div className="flex h-6 w-6 items-center justify-center rounded-full bg-blue-100 text-xs font-medium text-blue-600">
                4
              </div>
              <div>
                <p className="font-medium">최종 확정</p>
                <p className="text-muted-foreground">모든 평가가 완료되면 최종 점수와 등급이 확정됩니다.</p>
              </div>
            </div>
          </div>
          
          {/* 집계 뷰 설명 추가 */}
          <div className="border-t pt-3 space-y-2">
            <h5 className="font-medium text-sm flex items-center gap-1">
              <Info className="h-3 w-3" />
              보기 모드
            </h5>
            <div className="space-y-2 text-xs">
              <div className="flex items-center gap-2">
                <List className="h-3 w-3 text-blue-600" />
                <span className="font-medium">상세 뷰:</span>
                <span className="text-muted-foreground">모든 평가 기록을 개별적으로 표시</span>
              </div>
              <div className="flex items-center gap-2">
                <BarChart3 className="h-3 w-3 text-purple-600" />
                <span className="font-medium">집계 뷰:</span>
                <span className="text-muted-foreground">동일 벤더의 여러 division 평가를 평균으로 통합</span>
              </div>
            </div>
          </div>
        </div>
      </PopoverContent>
    </Popover>
  )
}

// 집계 모드 안내 컴포넌트
function AggregatedModeNotice({ isAggregated }: { isAggregated: boolean }) {
  if (!isAggregated) return null;
  
  return (
    <Alert className="mb-4 border-purple-200 bg-purple-50">
      <BarChart3 className="h-4 w-4 text-purple-600" />
      <AlertDescription className="text-purple-800">
        현재 <strong>집계 뷰</strong>로 표시되고 있습니다. 
        동일 벤더의 여러 division 평가 결과가 평균으로 통합되어 표시됩니다.
      </AlertDescription>
    </Alert>
  );
}

export default async function PeriodicEvaluationsPage(props: PeriodicEvaluationsPageProps) {
  const searchParams = await props.searchParams
  const {lng} = await props.params
  const {t} = await useTranslation(lng, 'menu')
  
  // ✅ nuqs 기반 파라미터 파싱
  const search = searchParamsEvaluationsCache.parse(searchParams)

  // 현재 평가년도
  const currentEvaluationYear = search.evaluationYear

  // ✅ 집계 모드를 지원하는 서비스 함수 사용
  const promises = Promise.all([
    getPeriodicEvaluationsWithAggregation(search)
  ])

  // ✅ 현재 모드 표시용 변수
  const currentMode = search.aggregated ? "집계" : "상세"

  return (
    <Shell className="gap-4">
      {/* 헤더 */}
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div className="flex items-center gap-2">
            <div className="flex items-center gap-2">
              <h2 className="text-2xl font-bold tracking-tight">
                {t('menu.vendor_management.evaluation')}
              </h2>
              <InformationButton pagePath="evcp/evaluation" />
              {/* <ProcessGuidePopover /> */}
            </div>
            <div className="flex items-center gap-2">
              <Badge variant="outline" className="text-sm">
                {currentEvaluationYear}년도
              </Badge>
              {/* ✅ 현재 보기 모드 표시 */}
              <Badge 
                variant={search.aggregated ? "default" : "secondary"} 
                className={`text-xs ${search.aggregated ? 'bg-purple-600' : ''}`}
              >
                <div className="flex items-center gap-1">
                  {search.aggregated ? (
                    <BarChart3 className="h-3 w-3" />
                  ) : (
                    <List className="h-3 w-3" />
                  )}
                  {currentMode} 뷰
                </div>
              </Badge>
            </div>
          </div>
        </div>
      </div>

      {/* ✅ 집계 모드 안내 */}
      <AggregatedModeNotice isAggregated={search.aggregated} />
             
      {/* 메인 테이블 */}
      <React.Suspense 
        // key={JSON.stringify(searchParams)} // 집계 모드 변경 시에도 리렌더링
        fallback={
          <DataTableSkeleton
            columnCount={search.aggregated ? 17 : 15} // 집계 모드에서 컬럼 추가
            searchableColumnCount={2}
            filterableColumnCount={8}
            cellWidths={[
              "3rem",   // checkbox
              "5rem",   // 평가년도
              "5rem",   // 평가기간 or 평가수 (집계 모드)
              "6rem",   // 구분 (집계 모드에서 더 넓게)
              "8rem",   // 벤더코드
              "12rem",  // 벤더명
              "4rem",   // 내외자
              "6rem",   // 자재구분
              "5rem",   // 문서제출
              "4rem",   // 제출일
              "4rem",   // 마감일
              "4rem",   // 총점
              "4rem",   // 등급
              "5rem",   // 진행상태
              "8rem",   // actions
              ...(search.aggregated ? ["5rem", "5rem"] : []) // 집계 모드 추가 컬럼
            ]}
            shrinkZero
          />
        }
      >
        <PeriodicEvaluationsTable
          promises={promises} 
          evaluationYear={currentEvaluationYear}
          // ✅ 현재 뷰 모드를 테이블 컴포넌트에 전달
          initialViewMode={search.aggregated ? "aggregated" : "detailed"}
        />
      </React.Suspense>
    </Shell>
  )
}